# ------------------------------------- #
# Replication code for:
#
# Pomeroy, Caleb "The Damocles Delusion: The Sense of Power Inflates Threat  
# Perception in World Politics," International Organization.
#
# This script reproduces the supplementary time pressure experiment results from the US.
# ------------------------------------- #


# --- set your working directory --- #
setwd("~/Downloads/damocles_delusion_replication/")

# --- libraries --- #
library(ggplot2)
library(texreg)
set.seed(1912)

# --- load data --- #
prolific_df <- readRDS("data/us_time_pressure_data.rds")
dim(prolific_df) # the supplementary time pressure experiment consists of N = 984 US-based respondents recruited from Prolific 
prolific_df$speed_trt <- factor(prolific_df$speed_trt, levels = c("control", "fast")) # experimental assignment to "control" (no time pressure) versus "fast" (20 second countdown) conditions
#prolific_df$age # age is on an eight point scale, where 1 = 18-24, 2 = 25-34, 3 = 35-44, 4 = 45-54, 5 = 55-64, 6 = 65-74, 7 = 75-84, 8 = 85 or older
prolific_df$gender <- factor(prolific_df$gender, levels = c("non_male", "male"))  # self-reported male (versus female or self-describe)
prolific_df$ethnicity <- factor(prolific_df$ethnicity, levels = c("non_white", "white")) # self-reported white (or non-white) respondent
prolific_df$education <- factor(prolific_df$education , levels = c("bachelors", "less_bachelors")) # whether the respondent has completed at least a four-year college degree ("bachelors") or not ("less_bachelors")
#prolific_df$ideology # self-reported political ideology (higher = more conservative)
#prolific_df$pid # self-reported party ID (higher = more Republican)
#prolific_df$rei1_1 # five-point (dis)agreement with "I don't like to do a lot of thinking" (already reverse-coded, so higher = more deliberative)
#prolific_df$rei1_5 # five-point (dis)agreement with "I try to avoid situations that require thinking in depth about something" (already reverse-coded, so higher = more deliberative)
#prolific_df$rei1_2 # five-point (dis)agreement with "I prefer complex to simple problems" (higher = more deliberative)
#prolific_df$rei1_3 # five-point (dis)agreement with "I trust my initial feelings about people" (higher = more intuitive)
#prolific_df$rei1_4 # five-point (dis)agreement with "I believe in trusting my hunches"  (higher = more intuitive)
#prolific_df$rei1_6 # five-point (dis)agreement with "I can usually feel when a person is right or wrong even if I can't explain how I know"  (higher = more intuitive)
#prolific_df$china_threat # seven-point (dis)agreement with "China poses a serious threat to U.S. security" (higher = more threatening assessments)
#prolific_df$china_intentions # seven-point (dis)agreement with "China harbors aggressive intentions towards the U.S." (higher = perceptions of more aggressive intentions)
#prolific_df$sense_power_wants # seven-point (dis)agreement with "The U.S. can get other countries to do what the U.S. wants" (higher = greater sense of power)
#prolific_df$sense_power_great  # seven-point (dis)agreement with "The U.S. has a great deal of military power compared to other countries" (higher = greater sense of power)

# --- create additive scales for various IVs of interest
prolific_df$sense_power_additive <- rowSums(cbind(prolific_df$sense_power_great, prolific_df$sense_power_wants))
prolific_df$rei_intuitive <- rowSums(cbind(prolific_df$rei1_3, prolific_df$rei1_4, prolific_df$rei1_6))
prolific_df$rei_deliberative <- rowSums(cbind(prolific_df$rei1_1, prolific_df$rei1_5, prolific_df$rei1_2))

# --- sample demographics --- #
# below are sample demographic stats mentioned in the appendix
table(prolific_df$gender)/nrow(prolific_df) # 54.8% male
sum(table(prolific_df$age)[1:2])/nrow(prolific_df) # 37.1% aged 18-34
sum(table(prolific_df$age)[3:5])/nrow(prolific_df) # 55.0% aged 35-64
sum(table(prolific_df$age)[6:8])/nrow(prolific_df) # 7.9% aged 65 or older
table(prolific_df$education)/nrow(prolific_df) # 53.3% have a four-year degree (or higher)

# --- regression models --- #
# this is a simple experiment that assesses whether experimentally induced intuitive thinking increases threat perception (i.e. the M --> Y segment of the paper's causal chain)
# the survey also included correlational measures of the sense of power, trait intuitive thinking, and trait deliberative thinking, providing further correlational evidence to complement the paper's experimental evidence
summary(mod_threat <- lm(china_threat ~ speed_trt + sense_power_additive + rei_intuitive + rei_deliberative + 
                           age + gender + ethnicity + education + ideology + pid, prolific_df))
summary(mod_intentions <- lm(china_intentions ~ speed_trt + sense_power_additive + rei_intuitive + rei_deliberative + 
                               age + gender + ethnicity + education + ideology + pid, prolific_df))

# --- appendix table A9
screenreg(list(mod_threat, mod_intentions))
# texreg(list(mod_threat, mod_intentions),
#        custom.coef.names = c("(Intercept)", "Fast Thinking Treatment", "Sense of US Power",
#                              "Trait Intuitive Thinking", "Trait Deliberative Thinking",
#                              "Age", "Male", "White", "No College Degree", "Conservative", "Republican"),
#        custom.model.names = c("China Serious Threat", "China Aggressive Intentions"))

